﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dbPoll_Application.Models.CustomQuestion>" validateRequest="false" %>
<%@ Import Namespace="dbPoll_Application.Helpers" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Edit Custom Question
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="pageHeadingContainer">
        <h2 class="pageHeading">Edit Question</h2>
    </div>
    <div id="contentContainer">
        <p>
           <%= Html.ActionLink("Polls > ", "Index", "Poll", null, new { @class = "breadcrumb" })%>
           <%= Html.ActionLink(ViewData["pollName"] + " > ", "Questions", "Poll", new { pollID = ViewData["pollID"], pollName = ViewData["pollName"] }, new { @class = "breadcrumb" })%>
           Question <%= Model.questionNumber %>
        </p>
    <script src="../../Scripts/EditMCQ.js" type="text/javascript"></script>
    
    <% Html.EnableClientValidation(); 
       var pollRoles = ViewData["pollRoles"] as ICollection<dbPoll_Application.Models.Role>;
       var pollCreator = new dbPoll_Application.Models.Role("Poll Creator");
       var pollAdministrator = new dbPoll_Application.Models.Role("Poll Administrator");
       DateTime? pollClose = ViewData["pollClose"] as DateTime?;
       DateTime? pollStart = ViewData["pollStart"] as DateTime?;
    %>
    <% if (Model.questionID < 0)
       {
           Html.RenderPartial("PageMenu", Model);
       } %>
    <% String actionName;
       if (Model.questionID < 0)
       {
           actionName = "AddCustom";
       }
       else {
           actionName = "UpdateCustom";
       } %>
    <%  using (Ajax.BeginForm(actionName, new AjaxOptions { OnSuccess = "onSubmitSuccess" }))
        { %>
       <input type="hidden" id="pollID" value="<%= ViewData["pollID"] %>" name="pollID" />
       <input type="hidden" id="pollName" value="<%= ViewData["pollName"] %>" name="pollName" />
       <% Html.RenderPartial("Question", Model); %>

       <div id="rightColumn">
       <% if (pollRoles.Contains(pollCreator)) { %>
       <div class="right">
       <%if ((pollRoles.Contains(pollCreator) || pollRoles.Contains(pollAdministrator)) && pollStart==null)
         {%>
            <ul class="rightColumnList" id="templateList">
             <li class="rightColumnListHeading"><h2>Templates</h2></li>
             <% foreach (var templateName in ViewData["templates"] as List<String>)
                { %>
                    <li class="rightColumnListItem templateListItem"><%= templateName%></li>
             <% } %></ul><%} %>
       </div>
       <% } %>
       <% Html.RenderPartial("QuestionObjects", Model); %>
       <% Html.RenderPartial("QuestionSettings", Model); %>
       <% Html.RenderPartial("ChartSettings", Model); %>
       </div>
       <div class="compareWith">
           <%= Html.HiddenFor(m => m.compareWith.questionID)%>
           <span>Compare with:</span>
           <% var compareWith = ViewData["compareWith"] as String; %>
           <span class="searchCompareWith"><%= compareWith.CropAndTrail(40, "...") %></span>
           <span class="searchXCompareWith"><input type="button" value="Search" id="searchCompareQuestion" /></span>
           <span class="deleteCompareWith"><input type="button" value="Clear" id="clearCompareQuestion" /></span>
           <span style="float:right; margin-right:5px">display chart <%= Html.CheckBoxFor(m => m.comparisonChart.active)%></span>
           <%= Html.HiddenFor(m => m.comparisonChart.chartID)%>
           <%= Html.HiddenFor(m => m.comparisonChart.chartType)%>
           <%= Html.HiddenFor(m => m.comparisonChart.valueType)%>
           <%= Html.HiddenFor(m => m.comparisonChart.colours)%>
       </div>
       <% } %>
       <% if (!(Model.questionID < 0))
          { %>
          <div id="convertToDemographicContainer">
              <span id="convertToDemographic">
                  <label>Convert to demographic question:</label>
                  <input type="hidden" id="hasCompare" value="<%=ViewData["hasCompare"]%>" />
                  <button id="convertToDemographicButton">Convert</button>
              </span>
          </div>
       <% 
          }
       
       %>
       <div class="clear"></div>
       </div> 
       <script type="text/javascript" >
           if (("<%= pollClose > DateTime.Now%>" == "True" && "<%=(!(pollRoles.Contains(pollCreator) || pollRoles.Contains(pollAdministrator)))%>" == "True")) {
               document.getElementById("convertToDemographicButton").disabled = true;
           } else {
               document.getElementById("convertToDemographicButton").disabled = false;
           }
       </script>    
</asp:Content>
